package com.titleevaluation.controller;

import com.titleevaluation.entity.CurrentQualifications;
import com.titleevaluation.service.CurrentQualificationsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/applications/{applicationId}/current-qualifications")
public class CurrentQualificationsController {

    private final CurrentQualificationsService currentQualificationsService;

    public CurrentQualificationsController(CurrentQualificationsService currentQualificationsService) {
        this.currentQualificationsService = currentQualificationsService;
    }

    @PostMapping
    public ResponseEntity<CurrentQualifications> createCurrentQualifications(@PathVariable Long applicationId, @RequestBody CurrentQualifications currentQualifications) {
        CurrentQualifications createdCurrentQualifications = currentQualificationsService.createCurrentQualifications(applicationId, currentQualifications);
        return ResponseEntity.ok(createdCurrentQualifications);
    }

    @GetMapping
    public ResponseEntity<List<CurrentQualifications>> getCurrentQualificationsByApplicationId(@PathVariable Long applicationId) {
        List<CurrentQualifications> currentQualifications = currentQualificationsService.getCurrentQualificationsByApplicationId(applicationId);
        return ResponseEntity.ok(currentQualifications);
    }

    @GetMapping("/{id}")
    public ResponseEntity<CurrentQualifications> getCurrentQualificationsById(@PathVariable Long id) {
        return currentQualificationsService.getCurrentQualificationsById(id)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }

    @PutMapping("/{id}")
    public ResponseEntity<CurrentQualifications> updateCurrentQualifications(@PathVariable Long id, @RequestBody CurrentQualifications currentQualifications) {
        CurrentQualifications updatedCurrentQualifications = currentQualificationsService.updateCurrentQualifications(id, currentQualifications);
        return ResponseEntity.ok(updatedCurrentQualifications);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteCurrentQualifications(@PathVariable Long id) {
        currentQualificationsService.deleteCurrentQualifications(id);
        return ResponseEntity.noContent().build();
    }
}

